home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / dsp / dspkgctr.z / dspkgctr / gcc / emit-rtl.c < prev    next >
C/C++ Source or Header  |  1992-06-08  |  41KB  |  1,667 lines

  1. /* Emit RTL for the GNU C-Compiler expander.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4.    $Id: emit-rtl.c,v 1.11 91/11/22 19:40:49 pete Exp $
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. /* Middle-to-low level generation of rtx code and insns.
  24.  
  25.    This file contains the functions `gen_rtx', `gen_reg_rtx'
  26.    and `gen_label_rtx' that are the usual ways of creating rtl
  27.    expressions for most purposes.
  28.  
  29.    It also has the functions for creating insns and linking
  30.    them in the doubly-linked chain.
  31.  
  32.    The patterns of the insns are created by machine-dependent
  33.    routines in insn-emit.c, which is generated automatically from
  34.    the machine description.  These routines use `gen_rtx' to make
  35.    the individual rtx's of the pattern; what is machine dependent
  36.    is the kind of rtx's they make and what arguments they use.  */
  37.  
  38. #include "config.h"
  39. #include <stdio.h>
  40. #include "gvarargs.h"
  41. #include "rtl.h"
  42. #include "regs.h"
  43. #if ! defined( _INTELC32_ )
  44. #include "insn-config.h"
  45. #else
  46. #include "iconfig.h"
  47. #endif
  48. #include "real.h"
  49.  
  50. #if ! defined( _MSDOS )
  51. #define max(A,B) ((A) > (B) ? (A) : (B))
  52. #define min(A,B) ((A) < (B) ? (A) : (B))
  53. #endif
  54.  
  55. /* This is reset to FIRST_PSEUDO_REGISTER at the start each function.
  56.    After rtl generation, it is 1 plus the largest register number used.  */
  57.  
  58. int reg_rtx_no = FIRST_PSEUDO_REGISTER;
  59.  
  60. /* This is *not* reset after each function.  It gives each CODE_LABEL
  61.    in the entire compilation a unique label number.  */
  62.  
  63. static int label_num = 1;
  64.  
  65. /* Value of `label_num' at start of current function.  */
  66.  
  67. static int first_label_num;
  68.  
  69. /* Nonzero means do not generate NOTEs for source line numbers.  */
  70.  
  71. static int no_line_numbers;
  72.  
  73. /* Commonly used rtx's, so that we only need space for one copy.
  74.    These are initialized once for the entire compilation.
  75.    All of these except perhaps fconst0_rtx and dconst0_rtx
  76.    are unique; no other rtx-object will be equal to any of these.  */
  77.  
  78. rtx pc_rtx;            /* (PC) */
  79. rtx cc0_rtx;            /* (CC0) */
  80. rtx cc1_rtx;            /* (CC1) (not actually used nowadays) */
  81. rtx const0_rtx;            /* (CONST_INT 0) */
  82. rtx const1_rtx;            /* (CONST_INT 1) */
  83. rtx fconst0_rtx;        /* (CONST_DOUBLE:SF 0) */
  84. rtx dconst0_rtx;        /* (CONST_DOUBLE:DF 0) */
  85.  
  86. /* All references to the following fixed hard registers go through
  87.    these unique rtl objects.  On machines where the frame-pointer and
  88.    arg-pointer are the same register, they use the same unique object.
  89.  
  90.    After register allocation, other rtl objects which used to be pseudo-regs
  91.    may be clobbered to refer to the frame-pointer register.
  92.    But references that were originally to the frame-pointer can be
  93.    distinguished from the others because they contain frame_pointer_rtx.
  94.  
  95.    In an inline procedure, the stack and frame pointer rtxs may not be
  96.    used for anything else.  */
  97. rtx stack_pointer_rtx;        /* (REG:Pmode STACK_POINTER_REGNUM) */
  98. rtx frame_pointer_rtx;        /* (REG:Pmode FRAME_POINTER_REGNUM) */
  99. rtx arg_pointer_rtx;        /* (REG:Pmode ARG_POINTER_REGNUM) */
  100. rtx struct_value_rtx;        /* (REG:Pmode STRUCT_VALUE_REGNUM) */
  101. rtx struct_value_incoming_rtx;    /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
  102. rtx static_chain_rtx;        /* (REG:Pmode STATIC_CHAIN_REGNUM) */
  103. rtx static_chain_incoming_rtx;    /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
  104.  
  105. /* The ends of the doubly-linked chain of rtl for the current function.
  106.    Both are reset to null at the start of rtl generation for the function.
  107.    
  108.    start_sequence saves both of these on `sequence_stack' and then
  109.    starts a new, nested sequence of insns.  */
  110.  
  111. static rtx first_insn = NULL;
  112. static rtx last_insn = NULL;
  113.  
  114. /* Stack of pending (incomplete) sequences saved by `start_sequence'.
  115.    This looks like
  116.    (INSN_LIST saved-first-insn
  117.               (INSN_LIST saved-last-insn ...more saved sequences...)).
  118.    The main insn-chain is saved in the last two links of the chain,
  119.    unless the chain is empty.  */
  120.  
  121. rtx sequence_stack = 0;
  122.  
  123. /* INSN_UID for next insn emitted.
  124.    Reset to 1 for each function compiled.  */
  125.  
  126. static int cur_insn_uid = 1;
  127.  
  128. /* Line number and source file of the last line-number NOTE emitted.
  129.    This is used to avoid generating duplicates.  */
  130.  
  131. static int last_linenum = 0;
  132. static char *last_filename = 0;
  133.  
  134. /* A vector indexed by pseudo reg number.  The allocated length
  135.    of this vector is regno_pointer_flag_length.  Since this
  136.    vector is needed during the expansion phase when the total
  137.    number of registers in the function is not yet known,
  138.    it is copied and made bigger when necessary.  */
  139.  
  140. char *regno_pointer_flag;
  141. int regno_pointer_flag_length;
  142.  
  143. /* Indexed by pseudo register number, gives the rtx for that pseudo.
  144.    Allocated in parallel with regno_pointer_flag.  */
  145.  
  146. rtx *regno_reg_rtx;
  147.  
  148. /* Filename and line number of last line-number note,
  149.    whether we actually emitted it or not.  */
  150. extern char *emit_filename;
  151. extern int emit_lineno;
  152.  
  153. rtx change_address ();
  154.  
  155. /* rtx gen_rtx (code, mode, [element1, ..., elementn])
  156. **
  157. **        This routine generates an RTX of the size specified by
  158. **    <code>, which is an RTX code.   The RTX structure is initialized
  159. **    from the arguments <element1> through <elementn>, which are
  160. **    interpreted according to the specific RTX type's format.   The
  161. **    special machine mode associated with the rtx (if any) is specified
  162. **    in <mode>.
  163. **
  164. **        gen_rtx() can be invoked in a way which resembles the lisp-like
  165. **    rtx it will generate.   For example, the following rtx structure:
  166. **
  167. **          (plus:QI (mem:QI (reg:SI 1))
  168. **               (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
  169. **
  170. **        ...would be generated by the following C code:
  171. **
  172. **            gen_rtx (PLUS, QImode,
  173. **            gen_rtx (MEM, QImode,
  174. **            gen_rtx (REG, SImode, 1)),
  175. **            gen_rtx (MEM, QImode,
  176. **            gen_rtx (PLUS, SImode,
  177. **                gen_rtx (REG, SImode, 2),
  178. **                gen_rtx (REG, SImode, 3)))),
  179. */
  180.  
  181. /*VARARGS2*/
  182. rtx
  183. #if defined( STDARGS_ARE_COOL )
  184. gen_rtx ( enum rtx_code code, ...)
  185. #else
  186. gen_rtx (va_alist)
  187.      va_dcl
  188. #endif
  189. {
  190.   va_list p;
  191. #if ! defined( STDARGS_ARE_COOL )
  192.   enum rtx_code code;
  193. #endif
  194.   enum machine_mode mode;
  195.   register int i;        /* Array indices...            */
  196.   register char *fmt;        /* Current rtx's format...        */
  197.   register rtx rt_val;        /* RTX to return to caller...        */
  198.  
  199. #if defined( STDARGS_ARE_COOL )
  200.   va_start (p, code);
  201. #else
  202.   va_start (p);
  203.   code = va_arg (p, enum rtx_code);
  204. #endif
  205.   mode = va_arg (p, enum machine_mode);
  206.  
  207.   if (code == CONST_INT)
  208.     {
  209.       int arg = va_arg (p, int);
  210.       if (arg == 0)
  211.     return const0_rtx;
  212.       if (arg == 1)
  213.     return const1_rtx;
  214.       rt_val = rtx_alloc (code);
  215.       INTVAL (rt_val) = arg;
  216.     }
  217.   else
  218.     {
  219.       rt_val = rtx_alloc (code);    /* Allocate the storage space.  */
  220.       rt_val->mode = mode;        /* Store the machine mode...  */
  221.  
  222.       fmt = GET_RTX_FORMAT (code);    /* Find the right format...  */
  223.       for (i = 0; i < GET_RTX_LENGTH (code); i++)
  224.     {
  225.       switch (*fmt++)
  226.         {
  227.         case '0':        /* Unused field.  */
  228.           break;
  229.  
  230.         case 'i':        /* An integer?  */
  231.           XINT (rt_val, i) = va_arg (p, int);
  232.           break;
  233.  
  234.         case 's':        /* A string?  */
  235.           XSTR (rt_val, i) = va_arg (p, char *);
  236.           break;
  237.  
  238.         case 'e':        /* An expression?  */
  239.         case 'u':        /* An insn?  Same except when printing.  */
  240.           XEXP (rt_val, i) = va_arg (p, rtx);
  241.           break;
  242.  
  243.         case 'E':        /* An RTX vector?  */
  244.           XVEC (rt_val, i) = va_arg (p, rtvec);
  245.           break;
  246.  
  247.         default:
  248.           abort();
  249.         }
  250.     }
  251.     }
  252.   va_end (p);
  253.   return rt_val;        /* Return the new RTX...        */
  254. }
  255.  
  256. /* gen_rtvec (n, [rt1, ..., rtn])
  257. **
  258. **        This routine creates an rtvec and stores within it the
  259. **    pointers to rtx's which are its arguments.
  260. */
  261.  
  262. /*VARARGS1*/
  263. rtvec
  264. #if defined( STDARGS_ARE_COOL )
  265. gen_rtvec ( int n, ... )
  266. #else
  267. gen_rtvec (va_alist)
  268.      va_dcl
  269. #endif
  270. {
  271. #if defined( STDARGS_ARE_COOL )
  272.   int i;
  273. #else
  274.   int n, i;
  275. #endif
  276.   va_list p;
  277.   rtx *vector;
  278.  
  279. #if defined( STDARGS_ARE_COOL )
  280.   va_start (p, n);
  281. #else
  282.   va_start (p);
  283.   n = va_arg (p, int);
  284. #endif
  285.  
  286.   if (n == 0)
  287.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  288.  
  289.   vector = (rtx *) alloca (n * sizeof (rtx));
  290.   for (i = 0; i < n; i++)
  291.     vector[i] = va_arg (p, rtx);
  292.   va_end (p);
  293.  
  294.   return gen_rtvec_v (n, vector);
  295. }
  296.  
  297. rtvec
  298. gen_rtvec_v (n, argp)
  299.      int n;
  300.      rtx *argp;
  301. {
  302.   register int i;
  303.   register rtvec rt_val;
  304.  
  305.   if (n == 0)
  306.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  307.  
  308.   rt_val = rtvec_alloc (n);    /* Allocate an rtvec...            */
  309.  
  310.   for (i = 0; i < n; i++)
  311.     rt_val->elem[i].rtx = *argp++;
  312.  
  313.   return rt_val;
  314. }
  315.  
  316. /* Generate a REG rtx for a new pseudo register of mode MODE.
  317.    This pseudo is assigned the next sequential register number.  */
  318.  
  319. rtx
  320. gen_reg_rtx (mode)
  321.      enum machine_mode mode;
  322. {
  323.   register rtx val;
  324.  
  325.   /* Make sure regno_pointer_flag and regno_reg_rtx are large
  326.      enough to have an element for this pseudo reg number.  */
  327.  
  328.   if (reg_rtx_no == regno_pointer_flag_length)
  329.     {
  330.       rtx *new1;
  331.       char *new =
  332.     (char *) oballoc (regno_pointer_flag_length * 2);
  333.       bzero (new, regno_pointer_flag_length * 2);
  334.       bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
  335.       regno_pointer_flag = new;
  336.  
  337.       new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));
  338.       bzero (new1, regno_pointer_flag_length * 2 * sizeof (rtx));
  339.       bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));
  340.       regno_reg_rtx = new1;
  341.  
  342.       regno_pointer_flag_length *= 2;
  343.     }
  344.  
  345.   val = gen_rtx (REG, mode, reg_rtx_no);
  346.   regno_reg_rtx[reg_rtx_no++] = val;
  347. #if defined( DSP56000 )
  348.   MEM_IN_STRUCT_P ( val ) = 0;
  349. #endif  
  350.   return val;
  351. }
  352.  
  353. /* Identify REG as a probable pointer register.  */
  354.  
  355. void
  356. mark_reg_pointer (reg)
  357.      rtx reg;
  358. {
  359.   REGNO_POINTER_FLAG (REGNO (reg)) = 1;
  360. }
  361.  
  362. /* Return 1 plus largest pseudo reg number used in the current function.  */
  363.  
  364. int
  365. max_reg_num ()
  366. {
  367.   return reg_rtx_no;
  368. }
  369.  
  370. /* Return 1 + the largest label number used so far.  */
  371.  
  372. int
  373. max_label_num ()
  374. {
  375.   return label_num;
  376. }
  377.  
  378. /* Return first label number used in this function (if any were used).  */
  379.  
  380. int
  381. get_first_label_num ()
  382. {
  383.   return first_label_num;
  384. }
  385.  
  386. /* Assuming that X is an rtx (MEM, REG or SUBREG) for a fixed-point number,
  387.    return a MEM or SUBREG rtx that refers to the least-significant part of X.
  388.    MODE specifies how big a part of X to return;
  389.    it must not be larger than a word.
  390.    If X is a MEM whose address is a QUEUED, the value may be so also.  */
  391.  
  392. rtx
  393. gen_lowpart (mode, x)
  394.      enum machine_mode mode;
  395.      register rtx x;
  396. {
  397.   /* This case loses if X is a subreg.  To catch bugs early,
  398.      complain if an invalid MODE is used even in other cases.  */
  399.   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
  400.       && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
  401.     abort ();
  402.   if (GET_MODE (x) == mode)
  403.     return x;
  404.   if (GET_CODE (x) == CONST_INT)
  405.     return gen_rtx (CONST_INT, VOIDmode, INTVAL (x) & GET_MODE_MASK (mode));
  406.   if (GET_CODE (x) == CONST_DOUBLE)
  407. /* In version 1.37, try this: */
  408. /*  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) abort (); */
  409.     /* Assume it's an int, so ..._LOW means the low-order word.  */
  410.     return gen_rtx (CONST_INT, VOIDmode,
  411.             CONST_DOUBLE_LOW (x) & GET_MODE_MASK (mode));
  412.   if (GET_CODE (x) == MEM)
  413.     {
  414.       register int offset = 0;
  415. #ifdef WORDS_BIG_ENDIAN
  416.       offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  417.         - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  418. #endif
  419. #ifdef BYTES_BIG_ENDIAN
  420.       /* Adjust the address so that the address-after-the-data
  421.      is unchanged.  */
  422.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  423.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  424. #endif
  425.       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
  426.     }
  427.   else if (GET_CODE (x) == SUBREG)
  428.     return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
  429.         ? SUBREG_REG (x)
  430.         : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
  431.   else if (GET_CODE (x) == REG)
  432.     {
  433. #ifdef WORDS_BIG_ENDIAN
  434.       if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  435.     {
  436.       return gen_rtx (SUBREG, mode, x,
  437.               ((GET_MODE_SIZE (GET_MODE (x))
  438.                 - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  439.                / UNITS_PER_WORD));
  440.     }
  441. #endif
  442.       return gen_rtx (SUBREG, mode, x, 0);
  443.     }
  444.   else
  445.     abort ();
  446. }
  447.  
  448. /* Like `gen_lowpart', but refer to the most significant part.  */
  449.  
  450. rtx
  451. gen_highpart (mode, x)
  452.      enum machine_mode mode;
  453.      register rtx x;
  454. {
  455.   if (GET_CODE (x) == MEM)
  456.     {
  457.       register int offset = 0;
  458. #ifndef WORDS_BIG_ENDIAN
  459.       offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  460.         - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  461. #endif
  462. #ifndef BYTES_BIG_ENDIAN
  463.       if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
  464.     offset -= (GET_MODE_SIZE (mode)
  465.            - min (UNITS_PER_WORD,
  466.               GET_MODE_SIZE (GET_MODE (x))));
  467. #endif
  468.       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
  469.     }
  470.   else if (GET_CODE (x) == REG)
  471.     {
  472. #ifndef WORDS_BIG_ENDIAN
  473.       if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  474.     {
  475.       return gen_rtx (SUBREG, mode, x,
  476.               ((GET_MODE_SIZE (GET_MODE (x))
  477.                 - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  478.                / UNITS_PER_WORD));
  479.     }
  480. #endif
  481.       return gen_rtx (SUBREG, mode, x, 0);
  482.     }
  483.   else
  484.     abort ();
  485. }
  486.  
  487. /* Return 1 iff X, assumed to be a SUBREG,
  488.    refers to the least significant part of its containing reg.
  489.    If X is not a SUBREG, always return 1 (it is its own low part!).  */
  490.  
  491. int
  492. subreg_lowpart_p (x)
  493.      rtx x;
  494. {
  495.   if (GET_CODE (x) != SUBREG)
  496.     return 1;
  497. #ifdef WORDS_BIG_ENDIAN
  498.   if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  499.     {
  500.       register enum machine_mode mode = GET_MODE (SUBREG_REG (x));
  501.       return (SUBREG_WORD (x)
  502.           == ((GET_MODE_SIZE (GET_MODE (x))
  503.            - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  504.           / UNITS_PER_WORD));
  505.     }
  506. #endif 
  507.   return SUBREG_WORD (x) == 0;
  508. }
  509.  
  510. /* Return a memory reference like MEMREF, but with its mode changed
  511.    to MODE and its address changed to ADDR.
  512.    (VOIDmode means don't change the mode.
  513.    NULL for ADDR means don't change the address.)  */
  514.  
  515. rtx
  516. change_address (memref, mode, addr)
  517.      rtx memref;
  518.      enum machine_mode mode;
  519.      rtx addr;
  520. {
  521.   rtx new;
  522.  
  523.   if (GET_CODE (memref) != MEM)
  524.     abort ();
  525.   if (mode == VOIDmode)
  526.     mode = GET_MODE (memref);
  527.   if (addr == 0)
  528.     addr = XEXP (memref, 0);
  529.  
  530.   new = gen_rtx (MEM, mode, memory_address (mode, addr));
  531.   MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
  532.   RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
  533.   MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
  534.   return new;
  535. }
  536.  
  537. /* Return a newly created CODE_LABEL rtx with a unique label number.  */
  538.  
  539. rtx
  540. gen_label_rtx ()
  541. {
  542.   register rtx label = gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++);
  543.   LABEL_NUSES (label) = 0;
  544.   return label;
  545. }
  546.  
  547. /* For procedure integration.  */
  548.  
  549. /* Return a newly created INLINE_HEADER rtx.  Should allocate this
  550.    from a permanent obstack when the opportunity arises.  */
  551.  
  552. rtx
  553. gen_inline_header_rtx (insn, last_insn,
  554.                first_labelno, last_labelno,
  555.                max_parm_regnum, max_regnum, args_size,
  556.                stack_slots)
  557.      rtx insn, last_insn;
  558.      int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
  559.      rtx stack_slots;
  560. {
  561.   rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
  562.             cur_insn_uid++, NULL,
  563.             insn, last_insn,
  564.             first_labelno, last_labelno,
  565.             max_parm_regnum, max_regnum, args_size, stack_slots);
  566.   return header;
  567. }
  568.  
  569. /* Install new pointers to the first and last insns in the chain.
  570.    Used for an inline-procedure after copying the insn chain.  */
  571.  
  572. void
  573. set_new_first_and_last_insn (first, last)
  574.      rtx first, last;
  575. {
  576.   first_insn = first;
  577.   last_insn = last;
  578. }
  579.  
  580. /* Go through all the RTL insn bodies and copy any invalid shared structure.
  581.    It does not work to do this twice, because the mark bits set here
  582.    are not cleared afterwards.  */
  583.  
  584. static int unshare_copies = 0;    /* Count rtx's that were copied.  */
  585.  
  586. static rtx copy_rtx_if_shared ();
  587.  
  588. void
  589. unshare_all_rtl (insn)
  590.      register rtx insn;
  591. {
  592.   extern rtx stack_slot_list;
  593.  
  594.   for (; insn; insn = NEXT_INSN (insn))
  595.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  596.     || GET_CODE (insn) == CALL_INSN)
  597.       {
  598.     PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
  599.     REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
  600.     LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
  601.       }
  602.  
  603.   /* Make sure the addresses of stack slots are not shared
  604.      with anything in the insn chain.  That could happen if
  605.      the stack slot is referenced only by its address.  */
  606.   copy_rtx_if_shared (stack_slot_list);
  607. }
  608.  
  609. /* Mark ORIG as in use, and return a copy of it if it was already in use.
  610.    Recursively does the same for subexpressions.  */
  611.  
  612. static rtx
  613. copy_rtx_if_shared (orig)
  614.      rtx orig;
  615. {
  616.   register rtx x = orig;
  617.   register int i;
  618.   register enum rtx_code code;
  619.   register char *format_ptr;
  620.   int copied = 0;
  621.  
  622.   if (x == 0)
  623.     return 0;
  624.  
  625.   code = GET_CODE (x);
  626.  
  627.   /* These types may be freely shared.  */
  628.  
  629.   switch (code)
  630.     {
  631.     case REG:
  632.     case QUEUED:
  633.     case CONST_INT:
  634.     case CONST_DOUBLE:
  635.     case SYMBOL_REF:
  636.     case CODE_LABEL:
  637.     case PC:
  638.     case CC0:
  639.       return x;
  640.  
  641.     case INSN:
  642.     case JUMP_INSN:
  643.     case CALL_INSN:
  644.     case NOTE:
  645.     case LABEL_REF:
  646.     case BARRIER:
  647.       /* The chain of insns is not being copied.  */
  648.       return x;
  649.  
  650.     case MEM:
  651.       /* A MEM is allowed to be shared if its address is constant
  652.      or is a constant plus one of the special registers.  */
  653.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  654.     return x;
  655.       if (GET_CODE (XEXP (x, 0)) == PLUS
  656.       && (XEXP (XEXP (x, 0), 0) == frame_pointer_rtx
  657.           || XEXP (XEXP (x, 0), 0) == arg_pointer_rtx)
  658.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  659.     {
  660.       /* This MEM can appear in more than one place,
  661.          but its address better not be shared with anything else.  */
  662.       if (! x->used)
  663.         XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
  664.       x->used = 1;
  665.       return x;
  666.     }
  667.       if (XEXP (x, 0) == frame_pointer_rtx
  668.       || XEXP (x, 0) == arg_pointer_rtx)
  669.     return x;
  670.     }
  671.  
  672.   /* This rtx may not be shared.  If it has already been seen,
  673.      replace it with a copy of itself.  */
  674.  
  675.   if (x->used)
  676.     {
  677.       register rtx copy;
  678.  
  679.       unshare_copies++;
  680.  
  681.       copy = rtx_alloc (code);
  682.       bcopy (x, copy, (sizeof (*copy) - sizeof (copy->fld)
  683.                + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
  684.       x = copy;
  685.       copied = 1;
  686.     }
  687.   x->used = 1;
  688.  
  689.   /* Now scan the subexpressions recursively.
  690.      We can store any replaced subexpressions directly into X
  691.      since we know X is not shared!  Any vectors in X
  692.      must be copied if X was copied.  */
  693.  
  694.   format_ptr = GET_RTX_FORMAT (code);
  695.  
  696.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  697.     {
  698.       switch (*format_ptr++)
  699.     {
  700.     case 'e':
  701.       XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
  702.       break;
  703.  
  704.     case 'E':
  705.       if (XVEC (x, i) != NULL)
  706.         {
  707.           register int j;
  708.  
  709.           if (copied)
  710.         XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  711.           for (j = 0; j < XVECLEN (x, i); j++)
  712.         XVECEXP (x, i, j)
  713.           = copy_rtx_if_shared (XVECEXP (x, i, j));
  714.         }
  715.       break;
  716.     }
  717.     }
  718.   return x;
  719. }
  720.  
  721. /* Copy X if necessary so that it won't be altered by changes in OTHER.
  722.    Return X or the rtx for the pseudo reg the value of X was copied into.
  723.    OTHER must be valid as a SET_DEST.  */
  724.  
  725. rtx
  726. make_safe_from (x, other)
  727.      rtx x, other;
  728. {
  729.   while (1)
  730.     switch (GET_CODE (other))
  731.       {
  732.       case SUBREG:
  733.     other = SUBREG_REG (other);
  734.     break;
  735.       case STRICT_LOW_PART:
  736.       case SIGN_EXTEND:
  737.       case ZERO_EXTEND:
  738.     other = XEXP (other, 0);
  739.     break;
  740.       default:
  741.     goto done;
  742.       }
  743.  done:
  744.   if ((GET_CODE (other) == MEM
  745.        && ! CONSTANT_P (x)
  746.        && GET_CODE (x) != CONST_DOUBLE
  747.        && GET_CODE (x) != REG
  748.        && GET_CODE (x) != SUBREG)
  749.       || (GET_CODE (other) == REG
  750.       && (REGNO (other) < FIRST_PSEUDO_REGISTER
  751.           || reg_mentioned_p (other, x))))
  752.     {
  753.       rtx temp = gen_reg_rtx (GET_MODE (x));
  754.       emit_move_insn (temp, x);
  755.       return temp;
  756.     }
  757.   return x;
  758. }
  759.  
  760. /* Emission of insns (adding them to the doubly-linked list).  */
  761.  
  762. /* Return the first insn of the current sequence or current function.  */
  763.  
  764. rtx
  765. get_insns ()
  766. {
  767.   return first_insn;
  768. }
  769.  
  770. /* Return the last insn emitted in current sequence or current function.  */
  771.  
  772. rtx
  773. get_last_insn ()
  774. {
  775.   return last_insn;
  776. }
  777.  
  778. /* Specify a new insn as the last in the chain.  */
  779.  
  780. void
  781. set_last_insn (insn)
  782.      rtx insn;
  783. {
  784.   if (NEXT_INSN (insn) != 0)
  785.     abort ();
  786.   last_insn = insn;
  787. }
  788.  
  789. /* Return a number larger than any instruction's uid in this function.  */
  790.  
  791. int
  792. get_max_uid ()
  793. {
  794.   return cur_insn_uid;
  795. }
  796.  
  797. rtx
  798. next_insn (insn)
  799.      rtx insn;
  800. {
  801.   if (insn) return NEXT_INSN (insn);
  802.   return 0;
  803. }
  804.  
  805. rtx
  806. previous_insn (insn)
  807.      rtx insn;
  808. {
  809.   if (insn) return PREV_INSN (insn);
  810.   return 0;
  811. }
  812.  
  813. /* Make and return an INSN rtx, initializing all its slots.
  814.    Store PATTERN in the pattern slots.
  815.    PAT_FORMALS is an idea that never really went anywhere.  */
  816.  
  817. static rtx
  818. make_insn_raw (pattern, pat_formals)
  819.      rtx pattern;
  820.      rtvec pat_formals;
  821. {
  822.   register rtx insn;
  823.  
  824.   insn = rtx_alloc(INSN);
  825.   INSN_UID(insn) = cur_insn_uid++;
  826.  
  827.   PATTERN (insn) = pattern;
  828.   INSN_CODE (insn) = -1;
  829.   LOG_LINKS(insn) = NULL;
  830.   REG_NOTES(insn) = NULL;
  831.  
  832.   return insn;
  833. }
  834.  
  835. /* Like `make_insn' but make a JUMP_INSN instead of an insn.  */
  836.  
  837. static rtx
  838. make_jump_insn_raw (pattern, pat_formals)
  839.      rtx pattern;
  840.      rtvec pat_formals;
  841. {
  842.   register rtx insn;
  843.  
  844.   insn = rtx_alloc(JUMP_INSN);
  845.   INSN_UID(insn) = cur_insn_uid++;
  846.  
  847.   PATTERN (insn) = pattern;
  848.   INSN_CODE (insn) = -1;
  849.   LOG_LINKS(insn) = NULL;
  850.   REG_NOTES(insn) = NULL;
  851.   JUMP_LABEL(insn) = NULL;
  852.  
  853.   return insn;
  854. }
  855.  
  856. /* Add INSN to the end of the doubly-linked list.
  857.    INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE.  */
  858.  
  859. static void
  860. add_insn (insn)
  861.      register rtx insn;
  862. {
  863.   PREV_INSN (insn) = last_insn;
  864.   NEXT_INSN (insn) = 0;
  865.  
  866.   if (NULL != last_insn)
  867.     NEXT_INSN (last_insn) = insn;
  868.  
  869.   if (NULL == first_insn)
  870.     first_insn = insn;
  871.  
  872.   last_insn = insn;
  873. }
  874.  
  875. /* Add INSN, an rtx of code INSN, into the doubly-linked list
  876.    after insn AFTER.  */
  877.  
  878. static void
  879. add_insn_after (insn, after)
  880.      rtx insn, after;
  881. {
  882.   NEXT_INSN (insn) = NEXT_INSN (after);
  883.   PREV_INSN (insn) = after;
  884.  
  885.   if (NEXT_INSN (insn))
  886.     PREV_INSN (NEXT_INSN (insn)) = insn;
  887.   else if (last_insn == after)
  888.     last_insn = insn;
  889.   else
  890.     {
  891.       rtx stack = sequence_stack;
  892.       /* Scan all pending sequences too.  */
  893.       for (; stack; stack = XEXP (XEXP (stack, 1), 1))
  894.     if (after == XEXP (XEXP (stack, 1), 0))
  895.       XEXP (XEXP (stack, 1), 0) = insn;
  896.     }
  897.  
  898.   NEXT_INSN (after) = insn;
  899. }
  900.  
  901. /* Delete all insns made since FROM.
  902.    FROM becomes the new last instruction.  */
  903.  
  904. void
  905. delete_insns_since (from)
  906.      rtx from;
  907. {
  908.   if (from == 0)
  909.     first_insn = 0;
  910.   else
  911.     NEXT_INSN (from) = 0;
  912.   last_insn = from;
  913. }
  914.  
  915. /* Move a consecutive bunch of insns to a different place in the chain.
  916.    The insns to be moved are those between FROM and TO.
  917.    They are moved to a new position after the insn AFTER.  */
  918.  
  919. void
  920. reorder_insns (from, to, after)
  921.      rtx from, to, after;
  922. {
  923.   /* Splice this bunch out of where it is now.  */
  924.   if (PREV_INSN (from))
  925.     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
  926.   if (NEXT_INSN (to))
  927.     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
  928.   if (last_insn == to)
  929.     last_insn = PREV_INSN (from);
  930.   if (first_insn == from)
  931.     first_insn = NEXT_INSN (to);
  932.  
  933.   /* Make the new neighbors point to it and it to them.  */
  934.   if (NEXT_INSN (after))
  935.     {
  936.       PREV_INSN (NEXT_INSN (after)) = to;
  937.       NEXT_INSN (to) = NEXT_INSN (after);
  938.     }
  939.   PREV_INSN (from) = after;
  940.   NEXT_INSN (after) = from;
  941.   if (after == last_insn)
  942.     last_insn = to;
  943. }
  944.  
  945. /* Emit an insn of given code and pattern
  946.    at a specified place within the doubly-linked list.  */
  947.  
  948. /* Make an instruction with body PATTERN
  949.    and output it before the instruction BEFORE.  */
  950.  
  951. rtx
  952. emit_insn_before (pattern, before)
  953.      register rtx pattern, before;
  954. {
  955.   register rtx insn;
  956.  
  957.   if (GET_CODE (pattern) == SEQUENCE)
  958.     {
  959.       register int i;
  960.       /* For an empty sequence, emit nothing.  */
  961.       if (XVEC (pattern, 0))
  962.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  963.       add_insn_after (XVECEXP (pattern, 0, i), PREV_INSN (before));
  964.       return PREV_INSN (before);
  965.     }
  966.  
  967.   insn = make_insn_raw (pattern, 0);
  968.  
  969.   PREV_INSN (insn) = PREV_INSN (before);
  970.   NEXT_INSN (insn) = before;
  971.  
  972.   if (PREV_INSN (insn))
  973.     NEXT_INSN (PREV_INSN (insn)) = insn;
  974.   else
  975.     first_insn = insn;
  976.   PREV_INSN (before) = insn;
  977.  
  978.   return insn;
  979. }
  980.  
  981. /* Make an instruction with body PATTERN and code JUMP_INSN
  982.    and output it before the instruction BEFORE.  */
  983.  
  984. rtx
  985. emit_jump_insn_before (pattern, before)
  986.      register rtx pattern, before;
  987. {
  988.   register rtx insn = make_jump_insn_raw (pattern, 0);
  989.  
  990.   PREV_INSN (insn) = PREV_INSN (before);
  991.   NEXT_INSN (insn) = before;
  992.  
  993.   if (PREV_INSN (insn))
  994.     NEXT_INSN (PREV_INSN (insn)) = insn;
  995.   else
  996.     first_insn = insn;
  997.   PREV_INSN (before) = insn;
  998.  
  999.   return insn;
  1000. }
  1001.  
  1002. /* Make an instruction with body PATTERN and code CALL_INSN
  1003.    and output it before the instruction BEFORE.  */
  1004.  
  1005. rtx
  1006. emit_call_insn_before (pattern, before)
  1007.      register rtx pattern, before;
  1008. {
  1009.   rtx insn = emit_insn_before (pattern, before);
  1010.   PUT_CODE (insn, CALL_INSN);
  1011.   return insn;
  1012. }
  1013.  
  1014. /* Make an insn of code INSN with body PATTERN
  1015.    and output it after the insn AFTER.  */
  1016.  
  1017. rtx
  1018. emit_insn_after (pattern, after)
  1019.      register rtx pattern, after;
  1020. {
  1021.   if (GET_CODE (pattern) == SEQUENCE)
  1022.     {
  1023.       register int i;
  1024.       /* For an empty sequence, emit nothing.  */
  1025.       if (XVEC (pattern, 0))
  1026.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  1027.       {
  1028.         add_insn_after (XVECEXP (pattern, 0, i), after);
  1029.         after = NEXT_INSN (after);
  1030.       }
  1031.       return after;
  1032.     }
  1033.   else
  1034.     {
  1035.       register rtx insn = make_insn_raw (pattern, 0);
  1036.       add_insn_after (insn, after);
  1037.       return insn;
  1038.     }
  1039. }
  1040.  
  1041. /* Make an insn of code JUMP_INSN with body PATTERN
  1042.    and output it after the insn AFTER.  */
  1043.  
  1044. rtx
  1045. emit_jump_insn_after (pattern, after)
  1046.      register rtx pattern, after;
  1047. {
  1048.   register rtx insn = make_jump_insn_raw (pattern, 0);
  1049.  
  1050.   add_insn_after (insn, after);
  1051.   return insn;
  1052. }
  1053.  
  1054. /* Make an insn of code BARRIER
  1055.    and output it after the insn AFTER.  */
  1056.  
  1057. rtx
  1058. emit_barrier_after (after)
  1059.      register rtx after;
  1060. {
  1061.   register rtx insn = rtx_alloc (BARRIER);
  1062.  
  1063.   INSN_UID (insn) = cur_insn_uid++;
  1064.  
  1065.   add_insn_after (insn, after);
  1066.   return insn;
  1067. }
  1068.  
  1069. /* Emit the label LABEL after the insn AFTER.  */
  1070.  
  1071. void
  1072. emit_label_after (label, after)
  1073.      rtx label, after;
  1074. {
  1075.   /* This can be called twice for the same label
  1076.      as a result of the confusion that follows a syntax error!
  1077.      So make it harmless.  */
  1078.   if (INSN_UID (label) == 0)
  1079.     {
  1080.       INSN_UID (label) = cur_insn_uid++;
  1081.       add_insn_after (label, after);
  1082.     }
  1083. }
  1084.  
  1085. /* Emit a note of subtype SUBTYPE after the insn AFTER.  */
  1086.  
  1087. void
  1088. emit_note_after (subtype, after)
  1089.      int subtype;
  1090.      rtx after;
  1091. {
  1092.   register rtx note = rtx_alloc (NOTE);
  1093.   INSN_UID (note) = cur_insn_uid++;
  1094.   XSTR (note, 3) = 0;
  1095.   XINT (note, 4) = subtype;
  1096.   add_insn_after (note, after);
  1097. }
  1098.  
  1099. /* Make an insn of code INSN with pattern PATTERN
  1100.    and add it to the end of the doubly-linked list.
  1101.    If PATTERN is a SEQUENCE, take the elements of it
  1102.    and emit an insn for each element.
  1103.  
  1104.    Returns the last insn emitted.  */
  1105.  
  1106. rtx
  1107. emit_insn (pattern)
  1108.      rtx pattern;
  1109. {
  1110.   rtx insn;
  1111.  
  1112.   if (GET_CODE (pattern) == SEQUENCE)
  1113.     {
  1114.       register int i;
  1115.       /* For an empty sequence, emit nothing.  */
  1116.       if (XVEC (pattern, 0))
  1117.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  1118.       add_insn (insn = XVECEXP (pattern, 0, i));
  1119.     }
  1120.   else
  1121.     {
  1122.       insn = make_insn_raw (pattern, NULL);
  1123.       add_insn (insn);
  1124.     }
  1125.   return insn;
  1126. }
  1127.  
  1128. /* Emit the insns in a chain starting with INSN.  */
  1129.  
  1130. rtx
  1131. emit_insns (insn)
  1132.      rtx insn;
  1133. {
  1134.   while (insn)
  1135.     {
  1136.       rtx next = NEXT_INSN (insn);
  1137.       add_insn (insn);
  1138.       insn = next;
  1139.     }
  1140. }
  1141.  
  1142. /* Make an insn of code JUMP_INSN with pattern PATTERN
  1143.    and add it to the end of the doubly-linked list.  */
  1144.  
  1145. rtx
  1146. emit_jump_insn (pattern)
  1147.      rtx pattern;
  1148. {
  1149.   if (GET_CODE (pattern) == SEQUENCE)
  1150.     return emit_insn (pattern);
  1151.   else
  1152.     {
  1153.       register rtx insn = make_jump_insn_raw (pattern, NULL);
  1154.       add_insn (insn);
  1155.       return insn;
  1156.     }
  1157. }
  1158.  
  1159. /* Make an insn of code CALL_INSN with pattern PATTERN
  1160.    and add it to the end of the doubly-linked list.  */
  1161.  
  1162. rtx
  1163. emit_call_insn (pattern)
  1164.      rtx pattern;
  1165. {
  1166.   if (GET_CODE (pattern) == SEQUENCE)
  1167.     return emit_insn (pattern);
  1168.   else
  1169.     {
  1170.       register rtx insn = make_insn_raw (pattern, NULL);
  1171.       add_insn (insn);
  1172.       PUT_CODE (insn, CALL_INSN);
  1173.       return insn;
  1174.     }
  1175. }
  1176.  
  1177. /* Add the label LABEL to the end of the doubly-linked list.  */
  1178.  
  1179. rtx
  1180. emit_label (label)
  1181.      rtx label;
  1182. {
  1183.   /* This can be called twice for the same label
  1184.      as a result of the confusion that follows a syntax error!
  1185.      So make it harmless.  */
  1186.   if (INSN_UID (label) == 0)
  1187.     {
  1188.       INSN_UID (label) = cur_insn_uid++;
  1189.       add_insn (label);
  1190.     }
  1191.   return label;
  1192. }
  1193.  
  1194. /* Make an insn of code BARRIER
  1195.    and add it to the end of the doubly-linked list.  */
  1196.  
  1197. rtx
  1198. emit_barrier ()
  1199. {
  1200.   register rtx barrier = rtx_alloc (BARRIER);
  1201.   INSN_UID (barrier) = cur_insn_uid++;
  1202.   add_insn (barrier);
  1203.   return barrier;
  1204. }
  1205.  
  1206. /* Make an insn of code NOTE
  1207.    with data-fields specified by FILE and LINE
  1208.    and add it to the end of the doubly-linked list,
  1209.    but only if line-numbers are desired for debugging info.  */
  1210.  
  1211. rtx
  1212. emit_line_note (file, line)
  1213.      char *file;
  1214.      int line;
  1215. {
  1216.   emit_filename = file;
  1217.   emit_lineno = line;
  1218.  
  1219. #if 0
  1220.   if (no_line_numbers)
  1221.     return 0;
  1222. #endif
  1223.  
  1224.   return emit_note (file, line);
  1225. }
  1226.  
  1227. /* Make an insn of code NOTE
  1228.    with data-fields specified by FILE and LINE
  1229.    and add it to the end of the doubly-linked list.
  1230.    If it is a line-number NOTE, omit it if it matches the previous one.  */
  1231.  
  1232. rtx
  1233. emit_note (file, line)
  1234.      char *file;
  1235.      int line;
  1236. {
  1237.   register rtx note;
  1238.  
  1239.   if (line > 0)
  1240.     {
  1241.       if (file && last_filename && !strcmp (file, last_filename)
  1242.       && line == last_linenum)
  1243.     return 0;
  1244.       last_filename = file;
  1245.       last_linenum = line;
  1246.     }
  1247.  
  1248.   if (no_line_numbers && line > 0)
  1249.     {
  1250.       cur_insn_uid++;
  1251.       return 0;
  1252.     }
  1253.  
  1254.   note = rtx_alloc (NOTE);
  1255.   INSN_UID (note) = cur_insn_uid++;
  1256.   XSTR (note, 3) = file;
  1257.   XINT (note, 4) = line;
  1258.   add_insn (note);
  1259.   return note;
  1260. }
  1261.  
  1262. /* Emit a NOTE, and don't omit it even if LINE it the previous note.  */
  1263.  
  1264. rtx
  1265. emit_line_note_force (file, line)
  1266.      char *file;
  1267.      int line;
  1268. {
  1269.   last_linenum = -1;
  1270.   return emit_line_note (file, line);
  1271. }
  1272.  
  1273. /* Cause next statement to emit a line note even if the line number
  1274.    has not changed.  This is used at the beginning of a function.  */
  1275.  
  1276. void
  1277. force_next_line_note ()
  1278. {
  1279.   last_linenum = -1;
  1280. }
  1281.  
  1282. /* Return an indication of which type of insn should have X as a body.
  1283.    The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN.  */
  1284.  
  1285. enum rtx_code
  1286. classify_insn (x)
  1287.      rtx x;
  1288. {
  1289.   if (GET_CODE (x) == CODE_LABEL)
  1290.     return CODE_LABEL;
  1291.   if (GET_CODE (x) == CALL)
  1292.     return CALL_INSN;
  1293.   if (GET_CODE (x) == RETURN)
  1294.     return JUMP_INSN;
  1295.   if (GET_CODE (x) == SET)
  1296.     {
  1297.       if (SET_DEST (x) == pc_rtx)
  1298.     return JUMP_INSN;
  1299.       else if (GET_CODE (SET_SRC (x)) == CALL)
  1300.     return CALL_INSN;
  1301.       else
  1302.     return INSN;
  1303.     }
  1304.   if (GET_CODE (x) == PARALLEL)
  1305.     {
  1306.       register int j;
  1307.       for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
  1308.     if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
  1309.       return CALL_INSN;
  1310.     else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  1311.          && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
  1312.       return JUMP_INSN;
  1313.     else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  1314.          && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
  1315.       return CALL_INSN;
  1316.     }
  1317.   return INSN;
  1318. }
  1319.  
  1320. /* Emit the rtl pattern X as an appropriate kind of insn.
  1321.    If X is a label, it is simply added into the insn chain.  */
  1322.  
  1323. void
  1324. emit (x)
  1325.      rtx x;
  1326. {
  1327.   enum rtx_code code = classify_insn (x);
  1328.  
  1329.   if (code == CODE_LABEL)
  1330.     emit_label (x);
  1331.   else if (code == INSN)
  1332.     emit_insn (x);
  1333.   else if (code == JUMP_INSN)
  1334.     {
  1335.       register rtx insn = emit_jump_insn (x);
  1336.       if (simplejump_p (insn) || GET_CODE (x) == RETURN)
  1337.     emit_barrier ();
  1338.     }
  1339.   else if (code == CALL_INSN)
  1340.     emit_call_insn (x);
  1341. }
  1342.  
  1343. /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR.
  1344.    Return an rtx containing data on any sequence already in progress.  */
  1345.  
  1346. rtx
  1347. start_sequence ()
  1348. {
  1349.   sequence_stack
  1350.     = gen_rtx (INSN_LIST, VOIDmode,
  1351.            first_insn, gen_rtx (INSN_LIST, VOIDmode,
  1352.                     last_insn, sequence_stack));
  1353.   first_insn = 0;
  1354.   last_insn = 0;
  1355.   return sequence_stack;
  1356. }
  1357.  
  1358. /* Set up the insn chain starting with FIRST
  1359.    as the current sequence, saving the previously current one.  */
  1360.  
  1361. void
  1362. push_to_sequence (first)
  1363.      rtx first;
  1364. {
  1365.   rtx last;
  1366.   for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
  1367.   sequence_stack
  1368.     = gen_rtx (INSN_LIST, VOIDmode,
  1369.            first_insn, gen_rtx (INSN_LIST, VOIDmode,
  1370.                     last_insn, sequence_stack));
  1371.   first_insn = first;
  1372.   last_insn = last;
  1373. }
  1374.  
  1375. /* After emitting to a sequence, restore previous saved state.
  1376.    The argument SAVED is no longer used.
  1377.  
  1378.    To get the contents of the sequence just made,
  1379.    you must call `gen_sequence' *before* calling here.  */
  1380.  
  1381. void
  1382. end_sequence (saved)
  1383.      rtx saved;
  1384. {
  1385.   first_insn = XEXP (sequence_stack, 0);
  1386.   last_insn = XEXP (XEXP (sequence_stack, 1), 0);
  1387.   sequence_stack = XEXP (XEXP (sequence_stack, 1), 1);
  1388. }
  1389.  
  1390. /* Generate a SEQUENCE rtx containing the insns already emitted
  1391.    to the current sequence.
  1392.  
  1393.    This is how the gen_... function from a DEFINE_EXPAND
  1394.    constructs the SEQUENCE that it returns.  */
  1395.  
  1396. rtx
  1397. gen_sequence ()
  1398. {
  1399.   rtx tem;
  1400.   rtvec newvec;
  1401.   int i;
  1402.   int len;
  1403.  
  1404.   /* Count the insns in the chain.  */
  1405.   len = 0;
  1406.   for (tem = first_insn; tem; tem = NEXT_INSN (tem))
  1407.     len++;
  1408.  
  1409.   /* For an empty sequence... */
  1410.   if (len == 0)
  1411.     return gen_rtx (SEQUENCE, VOIDmode, NULL);
  1412.  
  1413.   /* If only one insn, return its pattern rather than a SEQUENCE.  */
  1414.   if (len == 1
  1415.       && (GET_CODE (first_insn) == INSN
  1416.       || GET_CODE (first_insn) == JUMP_INSN
  1417.       || GET_CODE (first_insn) == CALL_INSN))
  1418.     return PATTERN (first_insn);
  1419.  
  1420.   /* Put them in a vector.  */
  1421.   newvec = rtvec_alloc (len);
  1422.   i = 0;
  1423.   for (tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
  1424.     newvec->elem[i].rtx = tem;
  1425.  
  1426.   /* Make a SEQUENCE from this vector.  */
  1427.   return gen_rtx (SEQUENCE, VOIDmode, newvec);
  1428. }
  1429.  
  1430. /* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag
  1431.    according to the chain of insns starting with FIRST.
  1432.  
  1433.    Also set cur_insn_uid to exceed the largest uid in that chain.
  1434.  
  1435.    This is used when an inline function's rtl is saved
  1436.    and passed to rest_of_compilation later.  */
  1437.  
  1438. static void restore_reg_data_1 ();
  1439.  
  1440. void
  1441. restore_reg_data (first)
  1442.      rtx first;
  1443. {
  1444.   register rtx insn;
  1445.   int i;
  1446.   register int max_uid = 0;
  1447.  
  1448.   for (insn = first; insn; insn = NEXT_INSN (insn))
  1449.     {
  1450.       if (INSN_UID (insn) >= max_uid)
  1451.     max_uid = INSN_UID (insn);
  1452.  
  1453.       switch (GET_CODE (insn))
  1454.     {
  1455.     case NOTE:
  1456.     case CODE_LABEL:
  1457.     case BARRIER:
  1458.       break;
  1459.  
  1460.     case JUMP_INSN:
  1461.     case CALL_INSN:
  1462.     case INSN:
  1463.       restore_reg_data_1 (PATTERN (insn));
  1464.       break;
  1465.     }
  1466.     }
  1467.  
  1468.   /* Don't duplicate the uids already in use.  */
  1469.   cur_insn_uid = max_uid + 1;
  1470.  
  1471.   /* If any regs are missing, make them up.  */
  1472.   for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++)
  1473.     if (regno_reg_rtx[i] == 0)
  1474.       regno_reg_rtx[i] = gen_rtx (REG, SImode, i);
  1475. }
  1476.  
  1477. static void
  1478. restore_reg_data_1 (orig)
  1479.      rtx orig;
  1480. {
  1481.   register rtx x = orig;
  1482.   register int i;
  1483.   register enum rtx_code code;
  1484.   register char *format_ptr;
  1485.  
  1486.   code = GET_CODE (x);
  1487.  
  1488.   switch (code)
  1489.     {
  1490.     case QUEUED:
  1491.     case CONST_INT:
  1492.     case CONST_DOUBLE:
  1493.     case SYMBOL_REF:
  1494.     case CODE_LABEL:
  1495.     case PC:
  1496.     case CC0:
  1497.     case LABEL_REF:
  1498.       return;
  1499.  
  1500.     case REG:
  1501.       if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
  1502.     {
  1503.       /* Make sure regno_pointer_flag and regno_reg_rtx are large
  1504.          enough to have an element for this pseudo reg number.  */
  1505.       if (REGNO (x) >= reg_rtx_no)
  1506.         {
  1507.           reg_rtx_no = REGNO (x);
  1508.  
  1509.           if (reg_rtx_no >= regno_pointer_flag_length)
  1510.         {
  1511.           int newlen = max (regno_pointer_flag_length * 2,
  1512.                     reg_rtx_no + 30);
  1513.           rtx *new1;
  1514.           char *new = (char *) oballoc (newlen);
  1515.           bzero (new, newlen);
  1516.           bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
  1517.  
  1518.           new1 = (rtx *) oballoc (newlen * sizeof (rtx));
  1519.           bzero (new1, newlen * sizeof (rtx));
  1520.           bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));
  1521.  
  1522.           regno_pointer_flag = new;
  1523.           regno_reg_rtx = new1;
  1524.           regno_pointer_flag_length = newlen;
  1525.         }
  1526.           reg_rtx_no ++;
  1527.         }
  1528.       regno_reg_rtx[REGNO (x)] = x;
  1529.     }
  1530.       return;
  1531.  
  1532.     case MEM:
  1533.       if (GET_CODE (XEXP (x, 0)) == REG)
  1534.     mark_reg_pointer (XEXP (x, 0));
  1535.       restore_reg_data_1 (XEXP (x, 0));
  1536.       return;
  1537.     }
  1538.  
  1539.   /* Now scan the subexpressions recursively.  */
  1540.  
  1541.   format_ptr = GET_RTX_FORMAT (code);
  1542.  
  1543.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  1544.     {
  1545.       switch (*format_ptr++)
  1546.     {
  1547.     case 'e':
  1548.       restore_reg_data_1 (XEXP (x, i));
  1549.       break;
  1550.  
  1551.     case 'E':
  1552.       if (XVEC (x, i) != NULL)
  1553.         {
  1554.           register int j;
  1555.  
  1556.           for (j = 0; j < XVECLEN (x, i); j++)
  1557.         restore_reg_data_1 (XVECEXP (x, i, j));
  1558.         }
  1559.       break;
  1560.     }
  1561.     }
  1562. }
  1563.  
  1564. /* Initialize data structures and variables in this file
  1565.    before generating rtl for each function.
  1566.    WRITE_SYMBOLS is nonzero if any kind of debugging info
  1567.    is to be generated.  */
  1568.  
  1569. void
  1570. init_emit (write_symbols)
  1571.      int write_symbols;
  1572. {
  1573.   first_insn = NULL;
  1574.   last_insn = NULL;
  1575.   sequence_stack = NULL;
  1576.   cur_insn_uid = 1;
  1577.   reg_rtx_no = FIRST_PSEUDO_REGISTER;
  1578.   last_linenum = 0;
  1579.   last_filename = 0;
  1580.   first_label_num = label_num;
  1581.  
  1582.   no_line_numbers = ! write_symbols;
  1583.   
  1584.   /* Init the tables that describe all the pseudo regs.  */
  1585.  
  1586.   regno_pointer_flag_length = FIRST_PSEUDO_REGISTER + 100;
  1587.  
  1588.   regno_pointer_flag 
  1589.     = (char *) oballoc (regno_pointer_flag_length);
  1590.   bzero (regno_pointer_flag, regno_pointer_flag_length);
  1591.  
  1592.   regno_reg_rtx 
  1593.     = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
  1594.   bzero (regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
  1595. }
  1596.  
  1597. /* Create some permanent unique rtl objects shared between all functions.  */
  1598.  
  1599. void
  1600. init_emit_once ()
  1601. {
  1602.   /* Create the unique rtx's for certain rtx codes and operand values.  */
  1603.  
  1604.   pc_rtx = gen_rtx (PC, VOIDmode);
  1605.   cc0_rtx = gen_rtx (CC0, VOIDmode);
  1606.  
  1607.   /* Don't use gen_rtx here since gen_rtx in this case
  1608.      tries to use these variables.  */
  1609.   const0_rtx = rtx_alloc (CONST_INT);
  1610.   INTVAL (const0_rtx) = 0;
  1611.   const1_rtx = rtx_alloc (CONST_INT);
  1612.   INTVAL (const1_rtx) = 1;
  1613.  
  1614.   fconst0_rtx = rtx_alloc (CONST_DOUBLE);
  1615.   dconst0_rtx = rtx_alloc (CONST_DOUBLE);
  1616.   {
  1617.     union real_extract u;
  1618. #ifdef REAL_IS_NOT_DOUBLE
  1619.     bzero (&u, sizeof u);
  1620.     u.d = REAL_VALUE_ATOF ("0");
  1621. #else
  1622.     u.d = 0;
  1623. #endif
  1624.  
  1625.     bcopy (&u, &CONST_DOUBLE_LOW (fconst0_rtx), sizeof u);
  1626.     CONST_DOUBLE_MEM (fconst0_rtx) = cc0_rtx;
  1627.     PUT_MODE (fconst0_rtx, SFmode);
  1628.  
  1629.     bcopy (&u, &CONST_DOUBLE_LOW (dconst0_rtx), sizeof u);
  1630.     CONST_DOUBLE_MEM (dconst0_rtx) = cc0_rtx;
  1631.     PUT_MODE (dconst0_rtx, DFmode);
  1632.   }
  1633.  
  1634.   stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
  1635.   frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
  1636. #ifdef STRUCT_VALUE
  1637.   struct_value_rtx = STRUCT_VALUE;
  1638. #else
  1639.   struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
  1640. #endif
  1641.  
  1642. #ifdef STRUCT_VALUE_INCOMING
  1643.   struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
  1644. #else
  1645. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  1646.   struct_value_incoming_rtx
  1647.     = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
  1648. #else
  1649.   struct_value_incoming_rtx = struct_value_rtx;
  1650. #endif
  1651. #endif
  1652.  
  1653.   static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
  1654.  
  1655. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  1656.   if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
  1657.     static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
  1658.   else
  1659. #endif
  1660.     static_chain_incoming_rtx = static_chain_rtx;
  1661.  
  1662.   if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
  1663.     arg_pointer_rtx = frame_pointer_rtx;
  1664.   else
  1665.     arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
  1666. }
  1667.